package com.xydtech.ecard.config.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.ecard.config.domain.EcardDeptPrdTypeList;
import com.xydtech.ecard.config.service.IEcardDeptPrdTypeListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 机构产品类型配置Controller
 *
 * @author JHON
 * @date 2021-12-24
 */
@Controller
@RequestMapping("/ecard/config/prdType")
public class EcardDeptPrdTypeListController extends BaseController {
    private String prefix = "ecard/config/prdType";

    @Autowired
    private IEcardDeptPrdTypeListService ecardDeptPrdTypeListService;


    /**
     * 修改机构产品类型配置
     */
    @GetMapping("/edit/{deptId}")
    public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap) {
        EcardDeptPrdTypeList ecardDeptPrdTypeList = ecardDeptPrdTypeListService.selectEcardDeptPrdTypeListByDeptId(deptId);
        if (ecardDeptPrdTypeList == null) {
            ecardDeptPrdTypeList = new EcardDeptPrdTypeList();
            ecardDeptPrdTypeList.setDeptId(deptId);
            mmap.put("ecardDeptPrdTypeList", ecardDeptPrdTypeList);
            return prefix + "/add";
        } else {
            mmap.put("ecardDeptPrdTypeList", ecardDeptPrdTypeList);
            return prefix + "/edit";
        }
    }

    /**
     * 修改保存机构产品类型配置
     */
    @RequiresPermissions("ecard:config:prd:edit")
    @Log(title = "机构产品类型配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardDeptPrdTypeList ecardDeptPrdTypeList) {
        return toAjax(ecardDeptPrdTypeListService.updateEcardDeptPrdTypeList(ecardDeptPrdTypeList));
    }

    /**
     * 新增保存机构产品类型配置
     */
    @RequiresPermissions("ecard/config:prdType:add")
    @Log(title = "机构产品类型配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardDeptPrdTypeList ecardDeptPrdTypeList) {
        return toAjax(ecardDeptPrdTypeListService.insertEcardDeptPrdTypeList(ecardDeptPrdTypeList));
    }
}
